#/***************************************************************************\
# * Copyright (C) by Keio University
# * CMakeLists.txt created in 07 2012.
# * Mail : fdesorbi@hvrl.ics.keio.ac.jp
# *
# * This file is part of the HVRL Engine Library.
# *
# * The HVRL Engine Library is free software; you can redistribute it and/or modify
# * it under the terms of the GNU Lesser General Public License as published by
# * the Free Software Foundation; either version 3 of the License, or
# * (at your option) any later version.
# *
# * The HVRL Engine Library is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# * GNU Lesser General Public License for more details.
# *
# * You should have received a copy of the GNU Lesser General Public License
# * along with this program.  If not, see <http://www.gnu.org/licenses/>.
# *
# ***************************************************************************/

SET(HVRL_INCLUDE_DIRS ${HVRL_INCLUDE_DIRS} "${CMAKE_CURRENT_SOURCE_DIR}/include" CACHE INTERNAL "")
SET(namelocal sensor)

PROJECT(HVRL_${namelocal})

SET(the_target "hvrl_${namelocal}")

INCLUDE_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}/include"
		    "${CMAKE_CURRENT_SOURCE_DIR}/src"
		    "${CMAKE_CURRENT_BINARY_DIR}")

INCLUDE_DIRECTORIES("${HVRL_SOURCE_DIR}/modules/common/include")
INCLUDE_DIRECTORIES("${HVRL_SOURCE_DIR}/modules/datatypes/include")


FILE(GLOB lib_hdrs include/hvrl/${namelocal}/Sensor.hpp include/hvrl/${namelocal}/SensorDriver.hpp)

IF(HVRL_BUILD_WITH_OPENNI)
SET(lib_srcs ${lib_srcs} src/OpenNISensorDriver.cpp  src/OpenNISensor.cpp)
FILE(GLOB lib_hdrs include/hvrl/${namelocal}/OpenNISensorDriver.hpp include/hvrl/${namelocal}/OpenNISensor.hpp)
ENDIF()

IF(HVRL_BUILD_WITH_DEPTHSENSE)
SET(lib_srcs ${lib_srcs} src/DepthSenseSensorDriver.cpp  src/DepthSenseSensor.cpp)
FILE(GLOB lib_hdrs include/hvrl/${namelocal}/DepthSenseSensorDriver.hpp include/hvrl/${namelocal}/DepthSenseSensor.hpp)
ENDIF()

foreach(d ${lib_hdrs_in})
	string(REPLACE ".in" "" lib_hdrs_in_output ${d})
	configure_file(${d} ${lib_hdrs_in_output})
	set(lib_hdrs ${lib_hdrs} ${lib_hdrs_in_output})
endforeach()

foreach(d ${lib_hdrs})
        if(d MATCHES "qt")
		SET(QT_HDRS ${QT_HDRS} "${d}")
	else()
		SET(CPP_HDRS ${CPP_HDRS} "${d}")

            endif()
    endforeach()

if(DEFINED QT_HDRS)
qt4_wrap_cpp(FOO_MOC_SRCS ${QT_HDRS})
endif()

SOURCE_GROUP("Src" FILES ${lib_srcs})
SOURCE_GROUP("Include" FILES ${lib_hdrs})

IF(NOT "${lib_srcs}" STREQUAL "")

IF(HVRL_BUILD_SHARED_LIBS)
        IF(MSVC)
            set_target_properties(${the_target} PROPERTIES DEFINE_SYMBOL CVAPI_EXPORTS)
        ELSE()
            add_definitions(-DCVAPI_EXPORTS)        
        ENDIF()
	ADD_LIBRARY(${the_target} ${lib_srcs} ${CPP_HDRS} ${FOO_MOC_SRCS})
ELSE()
	ADD_LIBRARY(${the_target} STATIC ${lib_srcs} ${CPP_HDRS} ${FOO_MOC_SRCS})
ENDIF()

TARGET_LINK_LIBRARIES(${the_target} ${HVRL_EXTERN_LIBS} ${HVRL_LIBS})

SET_TARGET_PROPERTIES(${the_target} PROPERTIES
        ARCHIVE_OUTPUT_DIRECTORY ${HVRL_LIB_INSTALL_PATH}
        RUNTIME_OUTPUT_DIRECTORY ${HVRL_BIN_INSTALL_PATH}
        INSTALL_NAME_DIR lib)

INSTALL(TARGETS ${the_target}
        RUNTIME DESTINATION ${HVRL_BIN_INSTALL_PATH}
        LIBRARY DESTINATION ${HVRL_LIB_INSTALL_PATH} COMPONENT main
        ARCHIVE DESTINATION ${HVRL_LIB_INSTALL_PATH} COMPONENT main)

SET(HVRL_LIBS ${HVRL_LIBS} ${the_target} CACHE INTERNAL "")
ENDIF(NOT "${lib_srcs}" STREQUAL "")

INSTALL(FILES ${lib_hdrs} DESTINATION ${HVRL_INCLUDE_INSTALL_PATH}/hvrl/${namelocal}/)

IF(HVRL_BUILD_TEST AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test)
	create_test(${namelocal} ${ARGN})
ENDIF()

ADD_SUBDIRECTORY(plugins)
